<!--  -->
<template>
  <div id="app">
    <el-container>
      <el-header>
        <div class="home_title">电商管理系统</div>
        <div class="home_loginout">
          <el-button @click="loginout()">退出登录</el-button>
        </div>
      </el-header>
      <el-container>
        <el-aside width="col_flag? '64px':'200px'">
           <div class="btn_coll" @click="btn_col"> |||</div>
          <el-menu
            background-color="#333744"
            text-color="#fff"
            active-text-color="#409EFF"
            :unique-opened="true"
            :collapse="col_flag"
            :collapse-transition="false"
            :router="true"
            :default-active = "routrState"
          >
            <el-submenu
              :index="item.id + ''"
              v-for="item in homeData"
              :key="item.id"
            >
              <template slot="title">
                <i :class="itemListIcon[item.id]"></i>
                <span>{{ item.authName }}</span>
              </template>
              <el-menu-item
                v-for="item1 in item.children"
                :key="item1.id"
                :index="item1.path "
                @click="saveState(item1.path)"
              >
                <template slot="title">
                  <i class="el-icon-menu"></i>
                  <span>{{ item1.authName }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
            <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
//这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
//例如：import 《组件名称》 from '《组件路径》';

export default {
  //import引入的组件需要注入到对象中才能使用

  components: {},
  created() {
    this.requestHomeData();
    this.routrState = window.sessionStorage.getItem("route")
  },
  data() {
    //这里存放数据
    return {
      homeData: [],
      itemListIcon: {
        1: "iconfont icon-yonghu",
        2: "iconfont icon-quanxian1",
        3: "iconfont icon-shangpin",
        4: "iconfont icon-dingdan",
        5: "iconfont icon-shuju",
      },
      col_flag:false,
      routrState:''
    };
  },
  methods: {
    loginout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async requestHomeData() {
      const { data } = await this.$http.get("/home");
      console.log(data);
      this.homeData = data;
    },
    btn_col(){
        this.col_flag = !this.col_flag
    },
    saveState(route){
      window.sessionStorage.setItem("route",route)
      this.routrState = route
    }
  },

  //监听属性 类似于data概念
  computed: {},
  //监控data中的数据变化
  watch: {},
  //方法集合

  //生命周期 - 创建完成（可以访问当前this实例）
};
</script>
<style  scoped lang="less">
body,
#app {
  height: 100vh;
  /* 可以设置100vh,但是设置100%失效 */
}
.el-header {
  background: #373d41;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .home_title {
    color: white;
    font-size: 20px;
  }
}

.el-container {
  background: violet;
  /* width: 100%; */
  height: 100%;
}
.el-aside {
  background: #333744;
}
.el-main {
  background: #eaedf1;
}
.iconfont{
    margin: 10px;
}
.el-menu{
    border-right: 0 ;
}
.btn_coll{
    width: 100%;
    height: 25px;
    line-height: 25px;
    cursor: pointer;
    background: #4A5064;
    text-align: center;
    letter-spacing: 0.2em;

}
</style>